var htmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
module.exports ={
    entry:"./src/app.js",
    output:{
        path:path.join(__dirname,'dist'),
        filename:'js/[name].bundle.js'
    },
    plugins:[
        new htmlWebpackPlugin({
            filename:'index.html',
            template:'index.html',
            inject:'body'
        })
    ],
    module:{
        rules:[
           
            
            {
                test:/\.js$/,
                exclude:path.resolve(__dirname,'node_modules'),
                include:path.resolve(__dirname,'src'),
                loader:'babel-loader',
                query:{
                    presets:['es2015']//指定需要使用的标准   需要安装
                }
            },
            {
                test: /\.css$/,
                use: [
                  'style-loader',
                  { loader: 'css-loader', options: { importLoaders: 1 } },
                  { loader: 'postcss-loader', 
                        options: { 
                            plugins: [
                                require('autoprefixer')({
                                    browsers:['last 5 versions']
                                }),
                            ]    
                      
                        } 
                    }
                ]
            },
            {
                test:/\.less$/,
                use: [
                    'style-loader',
                    { loader: 'postcss-loader', 
                    options: { 
                        plugins: [
                            require('autoprefixer')({
                                browsers:['last 5 versions']
                            }),
                        ]    
                  
                    } 
                    },
                    "less-loader"
                ]
              
            },
            {
                test:/\.html$/,
                loader:'html-loader'
            },
            {
                test:/\.tpl$/,
                loader:'ejs-loader'
            },
            {
                test: /\.(png|gif|jpg|svg|jpeg)$/i,
                use: [
                    {
                        loader: 'url-loader',
                        query : {
                                  name : 'assets/[hash].[ext]',
                                  limit:20000
                        }
                  },
                    {
                      loader: 'image-webpack-loader',
                      options: {
                        mozjpeg: {
                          progressive: true,
                          quality: 65
                        },
                        // optipng.enabled: false will disable optipng
                        optipng: {
                          enabled: false,
                        },
                        pngquant: {
                          quality: '65-90',
                          speed: 4
                        },
                        gifsicle: {
                          interlaced: false,
                        },
                        // the webp option will enable WEBP
                        webp: {
                          quality: 75
                        }
                      }
                    },
                  ]
            }
        ]
    }
    
}